package org.come.Jpanel;

import com.tool.image.ImageMixDeal;
import com.updateNew.MyIsif;
import come.tool.Fighting.FightingMixDeal;
import come.tool.Fighting.Fightingimage;
import come.tool.Fighting.TypeState;
import org.come.Frame.TestSetupJframe;
import org.come.entity.Mount;
import org.come.entity.RoleSummoning;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;



class MyRendererxL extends JPanel implements ListCellRenderer
{
    private int index;
    public static String vs;
    private static JList<String> listpet;

    public MyRendererxL() {
    }

    public MyRendererxL(final int index) {
        this.index = index;
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(this.getWidth(), 24);
    }

    @Override
    public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
        final MyRendererxL mr = new MyRendererxL(index);
        mr.removeAll();
        if (mountJPanel.idx == index || isSelected) {
            mr.setBackground(Color.GRAY);
        }
        else {
            mr.setOpaque(false);
        }
        mr.setLayout(new FlowLayout(0));
        final Box box = Box.createHorizontalBox();
        box.add(new JLabel() {
            {
                this.setForeground(Color.BLACK);
                this.setText("");
                if (ImageMixDeal.userimg.getRoleShow().getFighting() != 0) {
                    final Fightingimage fightingimage = FightingMixDeal.getdata(0);
                    final List<TypeState> data = fightingimage.getFightingManData().cxxx("召唤兽");
                    final Map<String, Integer> map = new HashMap<String, Integer>() {
                        {
                            final Iterator<RoleSummoning> iterator = UserMessUntil.getPetListTable().iterator();
                            while (iterator.hasNext()) {
                                final RoleSummoning roleSummoning = (RoleSummoning)iterator.next();
                                final Iterator<TypeState> iterator2 = data.iterator();
                                while (iterator2.hasNext()) {
                                    final TypeState datum = (TypeState)iterator2.next();
                                    if (datum.getType().equals(roleSummoning.getSid().toString())) {
                                        this.put(roleSummoning.getSummoningname(), Integer.valueOf(datum.getState()));
                                    }
                                }
                            }
                        }
                    };
                    final int sid = UserMessUntil.getChosePetMes().getSid().intValue();
                    int i = 0;
                    while (i < data.size()) {
                        if (UserMessUntil.getChosePetMes() == null) {
                            if (((Integer)map.get(value.toString())).intValue() != 0) {
                                this.setForeground(Color.red);
                            }
                            else {
                                if (sid == Integer.parseInt(((TypeState)data.get(i)).getType())) {
                                    this.setForeground(Color.white);
                                }
                            }
                        }
                        ++i;
                    }
                }
            }
        });
        mr.add((Component)box);
        return (Component)mr;
    }

    final ImageIcon peiimg_sm = new ImageIcon("skin/8100226/newbutton/K159.png");

    final ImageIcon peiimg_hm = new ImageIcon("inkImg/hongmu/1/ss544.png");

    Color color = new Color(255, 255, 255);

    final Font fon1t = new Font("宋体", 0, 13);

    final Font font = new Font("宋体", 0, 12);

    @Override
    protected void paintComponent(final Graphics g) {
        super.paintComponent(g);
        final Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        if("水墨UI".equals(MyIsif.getStyle())) {
            g.drawImage(peiimg_sm.getImage(), 1, 5, 17, 17, null);
            g2d.setFont(fon1t);
            g2d.setColor(color);
        }else{

            g.drawImage(peiimg_hm.getImage(), 1, 5, 17, 17, null);
            final Font fon1t = new Font("宋体", 0, 13);
            g2d.setFont(fon1t);
            g2d.setColor(new Color(187, 165, 75));
        }
        if (this.index >= 9) {
            g2d.drawString(this.index + 1 + "", 2, 18);
        }
        else {
            g2d.drawString(this.index + 1 + "", 5, 18);
        }
        if (this.index <= 1) {
            g2d.drawString(this.index + 1 + "", 5, 18);
        }

        g2d.setFont(font);
        g2d.setColor(Color.white);
        final RoleSummoning pet = (RoleSummoning)UserMessUntil.getPetListTable().get(this.index);
        final Mount mount2 = ZhuJpanel.getPetMount(pet.getSid());
        if (mount2 != null) {
            g2d.setColor(Color.yellow);
            g2d.setFont(font);
            g2d.drawString(mount2.getMountname(), 128, 17);
            this.setBackground(Color.red);
        }
        String summoningname = ((RoleSummoning) UserMessUntil.getPetListTable().get(this.index)).getSummoningname();
        if(summoningname.length() >=7){
            summoningname =  summoningname.substring(0,7);
            summoningname+="..";
        }
        MyRendererxL.vs = ((RoleSummoning)UserMessUntil.getPetListTable().get(this.index)).getSummoningname();
        g2d.drawString(summoningname, 20, 17);
    }
}
